//
// Created by Soar Qin on 2017/8/18.
// Copyright (c) 2017 Soar Qin. All rights reserved.
//

#pragma once

#include "io_event.hh"

namespace core::async {

class Loop;

struct TimerContext;

class Timer: public IoEvent {
    DISABLE_CLASS_COPY(Timer);
public:
    explicit Timer(Loop &loop);
    ~Timer() override;

    bool start(uint64_t interval, uint64_t repeat = 0);
    void stop();
    bool restart(uint64_t interval, uint64_t repeat = 0);

    virtual void onTimer() = 0;

protected:
    void onEvent(short events) override;
    TimerContext *timer_;
};

}
